<title>Store | Update</title>
<h1>Update Store</h1>
<script>
    $(function() {
        var allStateObj = eval('<?= $this->allState ?>');
        var allCityObj = eval('<?= $this->allCity ?>');
        var allZipObj = eval('<?= $this->allZip ?>');

        $("select[name='state']").empty();
        $("select[name='city']").empty();
        $("select[name='zip']").empty();
        $("select[name='state']").append("<option value=''></option>");
        for (var i1 = 0; i1 < allStateObj.length; i1++) {
            $("select[name='state']").append("<option value='" + allStateObj[i1].id + "'>" + allStateObj[i1].name + "</option>");
        }

        $("select[name='city']").append("<option value=''></option>");
        $("select[name='zip']").append("<option value=''></option>");

        //load city
        $("select[name='state']").change(function() {
            $("select[name='city']").empty();
            $("select[name='zip']").empty();
            $("select[name='city']").append("<option value=''>Choose City</option>");
            var id = $(this).find("option:selected").attr('value');
            for (var i2 = 0; i2 < allCityObj.length; i2++) {
                if (allCityObj[i2].state_id === id) {
                    $("select[name='city']").append("<option value='" + allCityObj[i2].id + "'>" + allCityObj[i2].name + "</option>");
                }
            }
        });

        //load zip
        $("select[name='city']").change(function() {
            $("select[name='zip']").empty();
            $("select[name='zip']").append("<option value=''>Choose Pincode</option>");
            var id = $(this).find("option:selected").attr('value');
            for (var i3 = 0; i3 < allZipObj.length; i3++) {
                if (allZipObj[i3].city_id === id) {
                    $("select[name='zip']").append("<option value='" + allZipObj[i3].id + "'>" + allZipObj[i3].code + "</option>");
                }
            }
        });

        //show updated infos
        $("select[name='state']").val(<?= $this->selectedState ?>);
        for (var i4 = 0; i4 < allCityObj.length; i4++) {
            if (allCityObj[i4].state_id == <?= $this->selectedState ?>) {
                $("select[name='city']").append("<option value='" + allCityObj[i4].id + "'>" + allCityObj[i4].name + "</option>");
            }
        }
        $("select[name='city']").val(<?= $this->selectedCity ?>);
        for (var i5 = 0; i5 < allZipObj.length; i5++) {
            if (allZipObj[i5].city_id == <?= $this->selectedCity ?>) {
                $("select[name='zip']").append("<option value='" + allZipObj[i5].id + "'>" + allZipObj[i5].code + "</option>");
            }
        }
        $("select[name='zip']").val(<?=$this->selectedZip?>);

    });
</script>
<div id="view-content">
    <div class="row-fluid">
        <div class="span6 well">
            <?= $this->form ?>
        </div>
    </div>
</div>